﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FasterFood
{
    public partial class ReviewOrder : UserControl
    {
        double total;



        public ReviewOrder()
        {
            InitializeComponent();
        }



        private void calculateTotal()
        {
            total = 0.00;
            for (int i = 0; i < Form1.theCart.Count(); i++)
            {
                total += Form1.theCart.ElementAt(i).getPrice();
            }
            this.label17.Text = "$" + ((decimal)total);
        }

        private void deleteItemClick(object sender, EventArgs e)
        {
            Button x = new Button();
            x = (Button)sender;
            Form1.theCart.RemoveAt(flowLayoutPanel1.Controls.IndexOf(x.Parent));
            flowLayoutPanel1.Controls.Remove(x.Parent);
            calculateTotal();
        }



        public void populateDisplay()
        {
            flowLayoutPanel1.Controls.Clear();
            int y = 3; 
            for (int i = 0; i < Form1.theCart.Count(); i++)
            {

                GroupBox groupBox2 = new GroupBox();
                PictureBox pictureBox3 = new PictureBox();
                Button button2 = new Button();
                // 
                // groupBox2
                // 
                groupBox2.Anchor = System.Windows.Forms.AnchorStyles.None;
                groupBox2.BackColor = System.Drawing.SystemColors.ControlLight;
                groupBox2.Controls.Add(pictureBox3);
                groupBox2.Controls.Add(button2);
                groupBox2.Location = new System.Drawing.Point(3, y);
                groupBox2.Name = "groupBox2";
                groupBox2.Size = new System.Drawing.Size(416, 119);
                groupBox2.TabIndex = 7;
                groupBox2.TabStop = false;
                // 
                // pictureBox3
                // 
                try
                {
                    pictureBox3.Image = System.Drawing.Image.FromFile(Form1.theCart.ElementAt(i).getImageLoc());
                }
                catch
                {
                    pictureBox3.Image = System.Drawing.Image.FromFile("../../images/noPhoto.jpg");
                }
                    pictureBox3.Location = new System.Drawing.Point(2, 11);
                pictureBox3.Name = "pictureBox3";
                pictureBox3.Size = new System.Drawing.Size(343, 102);
                pictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
                pictureBox3.TabIndex = 6;
                pictureBox3.TabStop = false;
                // 
                // button2
                // 
                button2.Image = System.Drawing.Image.FromFile("../../images/deleteItem.png");
                button2.Location = new System.Drawing.Point(363, 49);
                button2.Name = "button2";
                button2.Size = new System.Drawing.Size(34, 41);
                button2.TabIndex = 5;
                button2.UseVisualStyleBackColor = true;
                button2.Click += new System.EventHandler(this.deleteItemClick);

                this.flowLayoutPanel1.Controls.Add(groupBox2);
                y += 120;
            }



        }

        private void changeOrderButton_Click(object sender, EventArgs e)
        {
            // hide current page and display main menu page
            Form1.foodPages[6].Visible = false;
            Form1.foodPages[1].Visible = true;
        }

        private void acceptOrderButton_Click(object sender, EventArgs e)
        {
            // hide current page and display payment page
            Form1.foodPages[6].Visible = false;
            Form1.foodPages[7].Visible = true;
        }

        private void ReviewOrder_VisibleChanged(object sender, EventArgs e)
        {
            calculateTotal();
            populateDisplay();
        }

        private void startOverBtn_Click(object sender, EventArgs e)
        {
            // hide current page and start over
            Form1.foodPages[6].Visible = false;
            Form1.foodPages[0].Visible = true;
        }

    }
}
